﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using Models;
using Web.SelfUtils;

namespace Web
{
    public partial class ProductType : System.Web.UI.Page
    {
        Pager pager;
        protected void Page_Load(object sender, EventArgs e)
        {
            pager = ViewState["pager"] as Pager;
            if (!IsPostBack)
            {
                int GoodsTypeID=0;
                if (Request.QueryString["GoodsTypeID"] != null)
                {
                    GoodsTypeID = int.Parse(Request.QueryString["GoodsTypeID"].ToString());
                }
                else
                {
                    Response.Write("<script>alert('操作错误!!!')</script>");
                }
                Pager pager1 = new Pager();
                ViewState["pager"] = pager1;
                selectTypeIDreAdd(GoodsTypeID, pager1);
                GoodsTypeBLL gb = new GoodsTypeBLL();
                List<GoodsTypeModels> list = gb.selectTypeID(GoodsTypeID);
                Label1.Text = list[0].GoodsTypeName.ToString();
            }
        }
        void selectTypeIDreAdd(int GoodsTypeID, Pager pager)
        {
            pager.Count = GoodsBLL.selectTypeAll(GoodsTypeID).Count;
            Label2.Text = string.Format("{0}/{1}", pager.PageIndex, pager.PageCount);
            GoodsBLL gb = new GoodsBLL();
            Repeater1.DataSource = gb.selectType(GoodsTypeID, pager.PageSize, pager.PageIndex);
            Repeater1.DataBind();
        }
        //首页
        protected void Button3_Click(object sender, EventArgs e)
        {
            int GoodsTypeID = 0;
            if (Request.QueryString["GoodsTypeID"] != null)
            {
                GoodsTypeID = int.Parse(Request.QueryString["GoodsTypeID"].ToString());
            }
            pager.FirstPage();
            selectTypeIDreAdd(GoodsTypeID, pager);
        }
        //上一页
        protected void Button4_Click(object sender, EventArgs e)
        {
            int GoodsTypeID = 0;
            if (Request.QueryString["GoodsTypeID"] != null)
            {
                GoodsTypeID = int.Parse(Request.QueryString["GoodsTypeID"].ToString());
            }
            pager.PrevPage();
            selectTypeIDreAdd(GoodsTypeID, pager);
        }
        //指定页
        protected void Button7_Click(object sender, EventArgs e)
        {
            if (TextBox1.Text.Trim() != "")
            {
                int GoodsTypeID = 0;
                if (Request.QueryString["GoodsTypeID"] != null)
                {
                    GoodsTypeID = int.Parse(Request.QueryString["GoodsTypeID"].ToString());
                }
                int i = int.Parse(TextBox1.Text.Trim());
                pager.ToPage(i);
                selectTypeIDreAdd(GoodsTypeID, pager);
            }

        }
        //下一页
        protected void Button5_Click(object sender, EventArgs e)
        {
            int GoodsTypeID = 0;
            if (Request.QueryString["GoodsTypeID"] != null)
            {
                GoodsTypeID = int.Parse(Request.QueryString["GoodsTypeID"].ToString());
            }
            pager.NextPage();
            selectTypeIDreAdd(GoodsTypeID, pager);
        }
        //尾页
        protected void Button6_Click(object sender, EventArgs e)
        {
            int GoodsTypeID =0;
            if (Request.QueryString["GoodsTypeID"] != null)
            {
                GoodsTypeID = int.Parse(Request.QueryString["GoodsTypeID"].ToString());
            }
            Pager pager = ViewState["pager"] as Pager;
            pager.LastPage();
            selectTypeIDreAdd(GoodsTypeID, pager);
        }
    }
}